<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>props 初体验</title>
</head>

<body>
    <div id="root"> </div>

    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>
    <!-- 1. 引入额外的 JS 文件 -->
    <script src="../js/prop-types.js"></script>

    <script type="text/babel">
        //声明一个变量
        let siqi = {
            name: '思琦',
            age: 17,
            gender: '女'
        };

        let yangjun = {
            gender: '男'
        }

        class Student extends React.Component{
            //2. 设置属性 名字是固定的
            static propTypes = {
                name: PropTypes.string,
                age: PropTypes.number,
                gender: PropTypes.string
            }

            //属性值的默认值设置
            static defaultProps = {
                name: '张三',
                age: 16
            }

            render(){
                console.log(this.props);
                return <ul>
                        <li>姓名: {this.props.name}</li>
                        <li>年龄: {this.props.age}</li>
                        <li>性别: {this.props.gender}</li>
                    </ul>
            }
        }

        //渲染
        ReactDOM.render(
            <div>
                <Student name={siqi.name} age={siqi.age} gender={siqi.gender} />
                <Student {...yangjun} />
            </div>,  document.querySelector("#root"));
    </script>
</body>

</html>